<?php

class IzmirPharmacyParser 
{
	private $rawdata;				     		
	
	public function parsePharmacies($rawdata)
	{	
		$this->rawdata = $rawdata;
		$dom = new DOMDocument('1.0', 'iso-8859-9');
		$dom->loadHTML($this->rawdata); // burada loadHtmlFile kullanilabilir.
		
		$pharmacyList = array();

		$domContainerPanel = $dom->getElementsByTagName("table");
		
		$pharmacyCount = $domContainerPanel->length; //eczane sayisi+3
		
		
		//start with 3-52
		if($pharmacyCount>3)
		{
			for($i=3; $i<$pharmacyCount;$i++)
			{
				$pharmacyRawList = $domContainerPanel->item($i)->getElementsByTagName("tr");
				
				//echo $pharmacyRawList->item(0)->childNodes->item(0)->nodeValue;
				$pharmacyName = $pharmacyRawList->item(1)->childNodes->item(0)->nodeValue.' ECZANESİ';
				//echo $pharmacyRawList->item(1)->childNodes->item(1)->nodeValue;
				$streetAddress = trim($pharmacyRawList->item(1)->childNodes->item(2)->nodeValue, "*");
				$pharmacyAddress = $streetAddress . ' ' . $pharmacyRawList->item(0)->childNodes->item(0)->nodeValue;
				$pharmacyAddress = str_replace('\'', '`', $pharmacyAddress);
				$pharmacyPhone = '0232'.$pharmacyRawList->item(1)->childNodes->item(3)->nodeValue;
				if($streetAddress != '') {
					array_push($pharmacyList, new Pharmacy($pharmacyName, $pharmacyPhone, $pharmacyAddress, 0, 0, 0));
				}
			}
		}
		return $pharmacyList;		
		
	}
	
}

?>